/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Scenery.Thing.Things;

import Scenery.Thing.Resource;
import com.jme3.bullet.collision.shapes.CollisionShape;
import com.jme3.bullet.collision.shapes.CompoundCollisionShape;
import com.jme3.bullet.control.RigidBodyControl;
import com.jme3.bullet.util.CollisionShapeFactory;
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.shape.Box;
import com.jme3.scene.shape.Cylinder;
import com.jme3.scene.shape.Sphere;
import jme3tools.optimize.GeometryBatchFactory;
import main.DumbMath;
import main.Main;

/**
 *
 * @author usuario
 * 
 */

public class TreeEntity extends Resource {

    private static CompoundCollisionShape collision = new CompoundCollisionShape();
    
    public TreeEntity() {
        super("tree");
    }
    
    @Override
    public void createEntity() {
        Sphere d = new Sphere(16,16, 1.3f);  
        Geometry leaves = new Geometry("leaves",d);
        leaves.setLocalTranslation(0,6,0);
        leaves.setMaterial(Main.getHandler().getAssetManager().loadMaterial("Materials/Leaves.j3m"));
        this.getEntityMasterNode().attachChild(leaves);
        
        Cylinder log = new Cylinder(10, 10, 0.4f,6f);
        Geometry gLog = new Geometry("log", log);
        gLog.setLocalRotation(DumbMath.PITCH090);
        //rootNode.addLight(al);
        gLog.setLocalTranslation(0,2,0);
        gLog.setMaterial(Main.getHandler().getAssetManager().loadMaterial("Materials/couro.j3m"));
        this.getEntityMasterNode().attachChild(gLog);
        gLog.setUserData("hits",0);
        gLog.setUserData("node", getEntityMasterNode());
        
        CollisionShape sceneShape =
        CollisionShapeFactory.createMeshShape(getEntityMasterNode());
        RigidBodyControl body = new RigidBodyControl(sceneShape, 0);
        getEntityMasterNode().addControl(body);
        
        
        //gLog.addControl(new RigidBodyControl(0));
        //gLog.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0,2,0));
        //GeometryBatchFactory.optimize(getEntityMasterNode());
        //getEntityMasterNode().setUserData("onHit","ChopTree");
        
    }

}
